#include<iostream>   
using namespace std;  
struct BTNode  
{  
    BTNode* lchild;  
    BTNode* rchild;  
    char data;  
};  
BTNode* CreateTree(char*in,char*pre,int n)  
{  
    if(n==0)  
    return NULL;  
    BTNode* T=new BTNode;  
    T->data=*pre;
	int i;    
    for(i=0;i<n;i++)  
    {  
        if(in[i]==*pre)  
        break;  
    }  
    T->lchild=CreateTree(in,pre+1,i);  
    T->rchild=CreateTree(in+i+1,pre+i+1,n-i-1);  
    return T;  
}  
int length(BTNode *T)  
{  
    if(T==NULL)  
    return 0;  
    int lchildh=length(T->lchild);  
    int rchildh=length(T->rchild);  
    if(lchildh>rchildh)
		return lchildh+1;
	else
		return rchildh+1; 
}  
int main()  
{  
    char in[10000],pre[10000];  
    int n;  
    cin>>n;  
    char ch;  
    for(int i=0;i<n;i++)  
    {  
        cin>>ch;  
        pre[i]=ch;  
    }  
    for(int i=0;i<n;i++)  
    {  
        cin>>ch;  
        in[i]=ch;  
    }  
    BTNode* Height=new BTNode;  
    Height=CreateTree(in,pre,n);  
    cout<<length(Height)<<endl;
	return 0;  
}  
